package com.tongzhan.controller;

import com.tongzhan.base.Return;
import com.tongzhan.service.InfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * 后台用户登录
 * @author htmic
 * @date 2020/8/10
 */
@RequestMapping("/user")
@RestController
public class LoginController {

    @Autowired
    private InfoService infoService;

    /**
     * 用户登录接口
     *
     * @param username 用户名
     * @param password 密码
     * @return Return
     */
    @PostMapping("/login")
    public Return login(HttpServletResponse response, String username, String password) {
        if (StringUtils.isEmpty(username) || "".equals(username.trim()) || StringUtils.isEmpty(password) || "".equals(password.trim())) {
            return new Return(Return.MISS_PARAM, "用户名和密码不能为空");
        }
        return infoService.login(response, username.trim(), password);
    }
}
